<template>
  <div style="line-height: 0;">
    <div style="margin-top: 15px; margin-bottom: 15px; line-height: 0; text-align: left;">
      <el-row>
        &nbsp;&nbsp;&nbsp;
        <label>操作人：</label>
        <el-input style="width: 200px;" prefix-icon="el-icon-search" v-model="params.username" placeholder="请输入操作人"></el-input>
          &nbsp;
        <el-button type="warning" round style="margin-left: 10px;" @click="findLog">查询</el-button>
        <el-button type="warning" round style="margin-left: 10px;" @click="reset">重置</el-button>
      </el-row>
    </div>
    <div >
      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column prop="log_id" v-if="false"></el-table-column>
        <el-table-column prop="log" label="操作内容" width="540"></el-table-column>
        <el-table-column prop="logtime" label="操作时间" width="180"></el-table-column>
        <el-table-column prop="username" label="操作人" width="180"></el-table-column>
        <el-table-column prop="ip" label="ip" width=""></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-popconfirm title="确定要删除吗?" @confirm="del(scope.row)">
              <el-button slot="reference" type="danger" style="margin-left: 5px;">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="text-align: center;">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>

</template>
<script>

import {queryLog} from "@/api/log";
import {list} from "postcss";
import request from "@/utils/request";

export default {
  computed: {
    list() {
      return list
    }
  },

  data() {
    return {
      params: {
        username:'',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      formLabelWidth: '190px',
    }
  },
  //在页面加载的时候，做一些事情
  created() {
    this.findLog();
  },
  //定义一些页面上触发事件调用的方法
  methods:{
    findLog(){
      queryLog(this.params).then(res => {
        if (res.code === '0'){
          this.tableData = res.data.list;
          this.total = res.data.total;
        } else{
          this.$message({
            message: res.msg,
            type: 'error'
          })
        }
      })
    },
    reset(){
      this.params = {
        pageNum: 1,
        pageSize: 10,
        username: '',
      }
      this.findLog();
    },
    del(log) {
      request.delete(`/log/del/${log.logId}`).then(res => {
        if (res.code === '0') {
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.findLog();
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      })
    },
    handleSizeChange(pageSize){
      this.params.pageSize = pageSize;
      this.findLog();
    },
    handleCurrentChange(pageNum){
      this.params.pageNum = pageNum;
      this.findLog();
    },
  }
}
</script>